﻿@{
    ViewBag.Title = "ResultIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;
<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    var _type = 2;
    $(function () {
        InitialPage();
        GetTree();
        GetDynamicCols();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                if (_type == "1") { $('#gridTable').setGridWidth(($('.gridPanel').width())); $("#gridTable").setGridHeight($(window).height() - 179.5); }
                else
                    $("#gridTable").setGridHeight($(window).height() - 171.5);
            }, 200);
            e.stopPropagation();
        });
        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "==请选择==",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree();
                    $('#btn_Search').trigger("click");
                }
            }
        });
        if (!!_organizeid)
            $('#PStructTree').ComboBoxTreeSetValue(_organizeid);
        //点击看板
        $("#time_see a.btn-default").click(function () {
            $("#time_see a.btn-default").removeClass("active");
            $(this).addClass("active");
            _type = $(this).attr("data-value");
            GetDynamicCols();
        });
        //查询事件
        $("#btn_Search").click(function () {
            GetDynamicCols();
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });

    }

    function GetTree() {
        $.ajax({
            type: "GET",
            async: false,
            url: "../../PropertyManage/SecurityPatrol/GetItemHtml?OrganizeId=" + _organizeid,
            success: function (data) {
                $("#Item").html("");
                $("#Item").append(data);
                $(".profile-nav li").click(function () {
                    $(".profile-nav li").removeClass("active");
                    $(".profile-nav li").removeClass("hover");
                    $(this).addClass("active");
                    GetDynamicCols();
                }).hover(function () {
                    if (!$(this).hasClass("active")) {
                        $(this).addClass("hover")
                    }
                }, function () {
                    $(this).removeClass("hover")
                })
            }
        });
    }

    function GetDynamicCols() {
        $('#gridTable').GridUnload();
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["type"] = _type;
        queryJson["SPIId"] = $(".profile-nav").find('li.active').attr('data-value');
        queryJson["OrganizeId"] = _organizeid;
        $.ajax({
            type: "GET",
            async: false,
            dataType: "json",
            data: { queryJson: JSON.stringify(queryJson) },
            url: "../../PropertyManage/SecurityPatrol/GetResultListJson",
            success: function (data) {
                creategrid(data);
            },
            beforeSend: function () {
                //$.jBox.tip("正在查询数据...", 'loading');
            }

        });
    }


    //加载表格
    function creategrid(data) {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            datatype: 'local',
            height: $(window).height() - 171.5,
            autowidth: true,
            colModel: data.ColMs,
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Name',
            sortorder: 'desc',
            unwritten: false,
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            loadtext: "正在加载数据......",
            jsonReader: {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: false
            },
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            ondblClickRow: function (rowid, iRow, iCol, e) {
                if (iCol < 6 || data.ColMs.length == iCol) return;
                var obj = $("#" + this.id).getRowData(rowid);
                var StartTime = $("#StartTime").val();
                top.tablist.newTab({ id: obj.id, title: '巡检明细【' + obj.Name + '】', closed: true, icon: "fa fa fa-eye", url: top.contentPath + '/PropertyManage/SecurityPatrol/Detail?SPLId=' + obj.SPLId + '&SPIId=' + obj.SPIId + '&type=' + _type + '&StartTime=' + StartTime + '&AddDate=' + (iCol - 6) + '&Name=' + encodeURI(encodeURI(obj.Name)) + '&PName=' + encodeURI(encodeURI(obj.PStructName)) });             
            }
        });
        $gridTable[0].addJSONData(data.Coldata);
        if (_type == "1") { $('#gridTable').setGridWidth(($('.gridPanel').width())); $("#gridTable").setGridHeight($(window).height() - 179.5); }
    }


</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height:98%;overflow-y:auto;">
            <div class="profile-nav">
                <ul style="padding-top: 20px;overflow:auto;" id="Item"></ul>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table id="queryCondition">
                        <tr style="padding-left: 10px;">
                            <td>所属机构：</td>
                            <td style="width:200px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></td>
                            <td style="padding-left: 10px;"> <input id="StartTime" readonly type="text" value="@LeSoft.Util.Time.GetDate(1 - Convert.ToInt32(DateTime.Now.DayOfYear))" class="form-control input-wdatepicker" onfocus="WdatePicker({})"></td>
                            <td style="text-align: center; padding-left: 5px;">至</td>
                            <td style="padding-left: 5px;"><input id="EndTime" readonly type="text" value="@DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.DayOfYear)).AddYears(1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({})"></td>
                            <td style="padding-left: 10px;">
                                <div id="time_see" class="btn-group">
                                    <a class="btn btn-default" data-value="1">日看板</a>
                                    <a class="btn btn-default active" data-value="2">月看板</a>
                                    <a class="btn btn-default" data-value="3">年看板</a>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                    </div>
                </div>
                <script>$('.toolbar').authorizeButton()</script>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
